package com.young.test.aop;

import org.apache.log4j.Logger;

import javax.inject.Named;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;

import com.young.test.util.DefaultUsageTracked;
import com.young.test.util.UsageTracked;


@Named
@Aspect
public class IntroductionAdvice {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(IntroductionAdvice.class);

	@DeclareParents(
			value="com.young.test.bean.ForAspectBean",
			defaultImpl=DefaultUsageTracked.class)
	public static UsageTracked mixin;
	
	@Before("com.young.test.aop.SystemArchitecture.forAspectBeanOperation() && this(usageTracked)")
	public void recordUsage(UsageTracked usageTracked){
		int count = usageTracked.incrementUseCount();
		logger.info("The usage count is :"+count);
	}
}
